package day2

import "fmt"

//	func val() {
//		i := GetValue()
//		switch i.(type) {
//		case int:
//			println("int")
//		case string:
//			println("string")
//		case interface{}:
//			println("interface")
//		default:
//			println("unknown")
//		}
//	}
//
//	func GetValue() int {
//		return 1
//	}
func hello(num ...int) {
	num[0] = 18
}
func Change() {
	i := []int{1, 23, 5}
	hello(i...)
	fmt.Println(i[0])
}
func f1() (r int) {
	defer func() {
		r++
	}()
	return 0
}

func f2() (r int) {
	t := 5
	defer func() {
		t = t + 5
	}()
	return t
}

func f3() (r int) {
	defer func(r int) {
		r = r + 5
	}(r)
	return 1
}

func f4() {
	type Person struct {
		age int
	}
	person := &Person{28}

	// 1.
	defer fmt.Println(person.age) //28

	// 2.
	defer func(p *Person) {
		fmt.Printf("%p", p)
		fmt.Println(p.age)
	}(person) // 29

	// 3.
	defer func() {
		fmt.Printf("%p", &person)
		fmt.Println(person.age)
	}() //

	person.age = 29
}

func f5() {
	type Person struct {
		age int
	}

	person := &Person{28}
	fmt.Printf("%p\n", person)
	// 1.
	defer fmt.Println(person.age)

	// 2.
	defer func(p *Person) {
		fmt.Printf("%p\n", p)
		fmt.Println(p.age)
	}(person)

	// 3.
	defer func() {
		fmt.Printf("%p\n", person)
		fmt.Println(person.age)
	}()

	person = &Person{29}
}
